<template>
	<view class="pages">
		<u-radio-group v-model="refundReason1" @change="radioGroupChange" :wrap='true' active-color="#002B56">
			<u-radio @change="radioChange" v-for="(item, index) in list" :key="index" :name="item.value"
				:disabled="item.disabled">
				<view class="tit">{{item.name}}</view>
			</u-radio>
		</u-radio-group>

		<view class="bott">
			<u-input v-model="refundReason2" :type="type" placeholder="填写退款申请理由（选填）" :border="border" :height="height"
				:auto-height="autoHeight" />
		</view>

		<view class="butIn" @click="ljsq">
			立即申请
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import API from "@/api/my.js"
	export default {
		data() {
			return {
				list: [],
				refundReason1: '1',
				refundReason2: '',
				type: 'textarea',
				border: true,
				height: 288,
				autoHeight: true,
				detectionOrderId: ''
			};
		},
		methods: {
			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				// console.log(e);
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				console.log(e);
			},
			refundReasonDict() {
				let token = uni.getStorage({
					token: token
				})
				API.refundReasonDict(token).then(res => {
					// this.dataList = res.data
					console.log(res)
					this.list = res.data;
				})
			},
			ljsq() {
				var data = {
					refundReason1: this.refundReason1,
					refundReason2: this.refundReason2,
					detectionOrderId: this.detectionOrderId
				}

				API.refund(data).then(res => {
					// this.dataList = res.data
					if (res.code == 200) {
						this.$refs.uToast.show({
							title: '退款成功',
							type: 'success',
							url: '/pagesB/refund/refund'
						})
					} else {
						this.$refs.uToast.show({
							title: '退款失败',
							type: 'error',
						})
					}
					console.log(res)
				})

			}

		},
		onLoad(option) {
			this.refundReasonDict();
			this.detectionOrderId = option.detectionOrderId
		}
	};
</script>
<style lang="scss">
	.pages {
		background: #fff;
		padding: 32rpx;
		height: 100vh;

		.u-radio {
			height: 108rpx;
			line-height: 108rpx;
			border-bottom: 1px solid #EFEFEF;
		}

		.tit {
			font-size: 28rpx;
			color: #2C2C2C;
			margin-left: 36rpx;
		}
	}

	.bott {
		width: 100%;
		margin-top: 32rpx;
	}

	.u-input__textarea {
		padding: 32rpx 24rpx !important;
	}

	.butIn {
		width: 686rpx;
		height: 88rpx;
		line-height: 88rpx;
		background: #002B56;
		font-size: 36rpx;
		color: #FFFFFF;
		border-radius: 8rpx;
		margin: 315rpx auto;
		text-align: center;
	}
</style>
